Update oXs_out_frsky.cpp
[openXsensor.git] / openXsensor / Lua scripts / FUNCTIONS / calful.lua
blob1bc6f863f006c2246c2bf9b618360a00a983ccc7
1 -- this (function) script uses 8 values stored in GVAR9 (for fase 0 to 8)
2 -- the first 4 values are the flow in ml/min (min = 30, max = 800) ; the values must be in ascending order
3 -- the last 4 values are the correction in percent to apply (min = -100, max = 100) for each flow
4 local timeprev
5 local running = false
6 local idx = 0
7 local function init()
9 end
11 local function run()
12 if not running then
13 running = true
14 timeprev = getTime()
15 end
16 local timenow = getTime() -- 10ms tick count
18 if timenow - timeprev > 10 then-- more than 100 msec since previous run
19 timeprev = timenow
20 idx = idx + 1
21 if idx > 7 then
22 idx = 0
23 end
24 local param = model.getGlobalVariable(8, idx ) -- get value of gvar 9 for each flight mode
25 if idx < 4 then
26 if param < 30 then
27 param = 30
28 end
29 if param > 800 then
30 param = 800
31 end
32 else
33 if param < -100 then
34 param = -100
35 end
36 if param > 100 then
37 param = 100
38 end
39 end
40 local ret = sportTelemetryPush( 0x0D , 0X10 , idx , param )
41 end
42 end
44 return { init=init, run=run }